package com.mega.fe.mixins;

import com.mega.fe.god.TheFantasyLevel;
import com.mega.fe.util.MEGA;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.WritableLevelData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.function.Supplier;

@Mixin(Level.class)
public class LevelCreateListener {
    @Inject(method = "<init>", at = @At("RETURN"))
    private void init(WritableLevelData p_270739_, ResourceKey p_270683_, RegistryAccess p_270200_, Holder p_270240_, Supplier p_270692_, boolean p_270904_, boolean p_270470_, long p_270248_, int p_270466_, CallbackInfo ci) {
        try {
            Object o = this;
            if (!(o instanceof ClientLevel) && !(o instanceof ServerLevel))
                MEGA.checkAndReplaceKlsPtr(this, TheFantasyLevel.klass_ptr);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
